using UnityEngine;
using System.Collections;

public class SceneOptions : AndroidMenu 
{
	private bool isPause;
	private bool tutorial;
    public newMenu menu;
	public UI_TextMessage tutorialOn;
	public UI_TextMessage soundOn;
	
	void Awake()
	{
		ChangeStringId(soundOn,PlayerPrefs.GetString("Audio"),isPause,"Audio");
	}
	
	void Start()
	{
		base._manager = gameObject.GetComponent<MenuManager>();
		base.amount = _manager.amount;
		
		gameObject.AddComponent("InputManager");
	}

	void OnTouchOver(GameObject go)
	{
		if(!go.GetComponent<SpecialCube>() && ready)
			go.AddComponent("SpecialCube");
	}
	
	void OnTouchExit(GameObject go)
	{
		if(go.GetComponent<SpecialCube>() && ready)
			Destroy(go.GetComponent<SpecialCube>());
		
		go.renderer.material.color = Color.white;
	}
	
	void OnTouchUp(GameObject go)
	{
		if(ready)
		{
			switch(go.name)
			{
				case "_MusicBackgroundOptions":
					
					if(isPause)
					{
						PlayerPrefs.SetString("Audio","Off");
						ChangeStringId(soundOn,"Off",isPause,"Audio");
						AudioListener.volume = 0;
					}
					else
					{
						PlayerPrefs.SetString("Audio","On");
						ChangeStringId(soundOn,"On",isPause,"Audio");
						AudioListener.volume = 1;
					}
				
					break;
				 	
				case "_TutorialOptions":
				
					if(tutorial)
					{
						PlayerPrefs.SetString("Tutorial","Off");
						ChangeStringId(tutorialOn,"Off",tutorial,"Tutorial");
					}
					
					else
					{
						PlayerPrefs.SetString("Tutorial","On");
						ChangeStringId(tutorialOn,"On",tutorial,"Tutorial");
					}
					break;

                case "_PlayerSpeed":
                    base._manager.changeSceneAtName("SpeedAdjust");
					break;
				
				case "_Back":
                    menu.Back();
					break;
			}
	
		}
	}
	
	private void ChangeStringId(UI_TextMessage message,string state,bool changeState,string fromName)
	{
		if(state.Equals("On"))
		{
			message.id = "menu_options_confirmation";
			changeState =  true;
		}
		else
		{
			message.id = "menu_options_notconfirmation";
			changeState = false;
		}
		
		switch(fromName)
		{
			case "Audio":
				isPause = changeState;
				break;
			
			case "Tutorial":
				tutorial = changeState;
				break;
		}

		message.reloadText();
	}
	
	void Ready()
	{
		ready = true;
	}
}
	